package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.request.ProjectMemberRequest;
import com.nbsaas.boot.project.data.entity.Project;
import com.nbsaas.boot.project.data.entity.ProjectMember;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 项目成员请求对象转换成实体对象
 */

public class ProjectMemberEntityConvert implements Converter<ProjectMember, ProjectMemberRequest> {

    @Override
    public ProjectMember convert(ProjectMemberRequest source) {
        ProjectMember result = new ProjectMember();
        BeanDataUtils.copyProperties(source, result);
        if (source.getMember() != null) {
            User member = new User();
            member.setId(source.getMember());
            result.setMember(member);
        }
        if (source.getProject() != null) {
            Project project = new Project();
            project.setId(source.getProject());
            result.setProject(project);
        }
        return result;
    }
}

